from apscheduler.executors.pool import ProcessPoolExecutor
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
# from apscheduler.executors.pool import ThreadPoolExecutor
def os_sqlite_path():
    # from pathlib import Path
    # db_path = Path(__file__).parent / "jobs.db"
    # return "sqlite:////" + str(db_path)
    # 在根目录生成数据库
    return "sqlite:///jobs.db"


class SchedulerSettings(object):
    JOBSTORES = {"default": SQLAlchemyJobStore(url=os_sqlite_path())}
    EXECUTORS = {
        "default": {"type": "threadpool", "max_workers": 20},
        "processpool": ProcessPoolExecutor(max_workers=5),
    }
    # EXECUTORS = {
    # 'default': ThreadPoolExecutor(20) 
    # }
    JOB_DEFAULTS = {"coalesce": False, "max_instances": 3}
    def dict(self):
        return {
            "jobstores": self.JOBSTORES,
            "executors": self.EXECUTORS,
            "job_defaults": self.JOB_DEFAULTS,
        }


settings = SchedulerSettings()
